/**
 * Created with JetBrains PhpStorm.
 * User: lunjiang
 * Date: 13-1-18
 * Time: 上午11:56
 * To change this template use File | Settings | File Templates.
 */
$(document).ready((function(){
    var chart;
    $(document).ready(function() {
        /**
         * data1 ,data2
         * data1: p级
         * data2: M级
         * key= p9
         * percent 百分比
         * num 人数
         * @type {Object}
         */
        //var data1 = {status:1,data:{P9:{percent:3,num:100},P8:{percent:10,num:200},P6:{percent:40,num:150}}};//p position
        var data1 = eval('('+p_list+')');
        //var data2 = {status:1,data:{M9:{percent:13,num:100},P8:{percent:20,num:200},P7:{percent:10,num:150},P6:{percent:1.1,num:150}}};//m position
        var data2 =eval('('+m_list+')');
        //console.log(p_list.data.length);
        if(!data1.data || !data2.data){
            $("#container").html('<div style="color: red;font:20px;margin: 100px auto 0;text-align: center;">暂无数据!!!</div>')
            $(".blockTip").hide();
            return;
        }
        var title = "安居客集团2013年第一季度，P线总人数为110，M线总人数为230";
        var result=[];
        for(var i in data1.data){
            result.push({name:i,y:data1.data[i].percent,color:'#abc1dc',num:data1.data[i].num});
        }
        for(var i in data2.data){
            result.push({name:i,y:data2.data[i].percent,color:'#4572a7',num:data2.data[i].num});
        }
            chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: ''
            },
                tooltip: {
                    enabled: true,
                    formatter: function() {
                        return this.point.name+"-"+this.point.y+"%,"+this.point.num+"人";
                    }
                },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        formatter: function() {
                            return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
                        }
                    }
                }
            },
                credits: {
                    enabled: false
                },
            series: [{
                type: 'pie',
                name: 'Browser share',
                data:result
            }]
        });
    });
})());